/* Copyright (c) 2008. International Fund Services (N.A.) L.L.C.
 * 1290 Avenue of the Americas 10th floor New York, NY 10104
 * All rights reserved.
 */

package org.dbwebx.dbunit;

import javax.sql.DataSource;

import org.dbunit.DataSourceDatabaseTester;
import org.dbunit.dataset.CompositeDataSet;
import org.dbunit.dataset.DataSetException;
import org.dbunit.dataset.IDataSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * The extended version of the {@link DataSourceDatabaseTester} supporting
 * adding several {@link IDataSet} to operation.
 * 
 * @author Izzet_Mustafayev
 * 
 */
public class MultyDataSetDataBaseTester extends DataSourceDatabaseTester {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = LoggerFactory
			.getLogger(MultyDataSetDataBaseTester.class);

	/**
	 * The constructor to create {@link MultyDataSetDataBaseTester} instance.
	 * 
	 * @param dataSource
	 *            the {@link DataSource} instance reference
	 */
	public MultyDataSetDataBaseTester(final DataSource dataSource) {
		super(dataSource);
	}

	/**
	 * Adds {@link IDataSet} to operation. Helps to combine several
	 * {@link IDataSet}s in one.
	 * 
	 * @param dataSet
	 *            the {@link IDataSet} to add
	 */
	public void addDataSet(final IDataSet dataSet) {
		IDataSet existingDataSet = getDataSet();

		if (null == existingDataSet) {
			setDataSet(dataSet);
		}

		if (null != existingDataSet) {
			try {
				setDataSet(new CompositeDataSet(new IDataSet[] { existingDataSet,
						dataSet }));
			} catch (DataSetException exc) {
				logger.error("Error occured on setting the dataset.", exc);
			}
		}
	}
}
